package edu.neusoft.yiqibike.controller;

import edu.neusoft.yiqibike.common.entity.mysql.Menu;
import edu.neusoft.yiqibike.common.entity.vo.Response;
import edu.neusoft.yiqibike.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单接口
 *
 * @author YooLin1c
 * @version 1.0.0
 * @since 2018-03-08 18:48
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    private IMenuService menuService;

    @Autowired
    public MenuController(IMenuService menuService) {
        this.menuService = menuService;
    }

    @GetMapping
    public Response<List<Menu>> menus() {
        return Response.success(menuService.getMenus());
    }

    @PostMapping("/")
    public Response<String> add(@RequestBody Menu menu) {
        return menuService.add(menu) ? Response.success() : Response.failed();
    }

    @PutMapping("/")
    public Response<String> edit(@RequestBody Menu menu) {
        return menuService.edit(menu) ? Response.success() : Response.failed();
    }
}
